<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>冀银科技-管理系统</title>
    <!--清理浏览器端缓存 -->
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- IE 以最高级模式渲染文档 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--width:可视区域的宽度，值可为数字或关键词device-width,maximum-scale=1.0将禁止用户放大到实际尺寸之上-->
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link rel="stylesheet" href="${basePath}/assets/css/bootstrap.min.css${VERSION}"/>
    <link rel="stylesheet" href="${basePath}/assets/css/font-awesome.min.css${VERSION}"/>
    <link rel="stylesheet" href="${basePath}/assets/css/font-awesome-ace.min.css${VERSION}"/>

    <script src="${basePath}/assets/js/jquery.min.js${VERSION}"></script>
    <script src="${basePath}/assets/js/bootstrap.min.js${VERSION}"></script>
    <script type="text/javascript" src="${basePath}/plugins/layer/layer.js${VERSION}"></script>
</head>
<body>
    <form enctype="multipart/form-data">
        <input name="file" type="file" webkitdirectory />
        <input type="button" value="Upload" />
    </form>
    <progress id="progressBar" value="0" max="100"></progress>

<script>
    var title = "sdasdas";
    $(':file').change(function(){
        var file = this.files;
        for (var i = 0; i < file.length; i++){
            var name = file[i].name;
            var size = file[i].size;
            var type = file[i].type;

            console.log("name=" + name + ", size=" + ", type=" + type);
        }
        //your validation
    });

    $(':button').click(function(){
        var formData = new FormData($('form')[0]);
        $.ajax({
            url: '${basePath}/deploy/deployFiles',  //server script to process data
            type: 'POST',
            xhr: function() {  // custom xhr
                myXhr = $.ajaxSettings.xhr();
                if(myXhr.upload){ // check if upload property exists
                    myXhr.upload.addEventListener('progress', progressHandler, false); // for handling the progress of the upload
                }
                return myXhr;
            },
            //Ajax事件
            //beforeSend: beforeSendHandler,
            success: function (data) {
                if(data.status == '0'){
                    successInfo(data.data);
                }else{
                    alertInfo(data.message);
                }
            },
            error: function (data) {
                alertInfo("系统异常!");
            },
            // Form数据
            data: formData,
            dataType: "json",
            //Options to tell JQuery not to process data or worry about content-type
            cache: false,
            contentType: false,
            processData: false
        });
    });

    function progressHandler(e){
        if(e.lengthComputable){
            $('#progressBar').attr({value: e.loaded, max: e.total});
        }
    }


    function alertInfo(info){
        layer.alert(info,{
            title: title,
            icon: 2,
            closeBtn: 1, //不显示关闭按钮
            anim: 6,
            shadeClose: true, //开启遮罩关闭
        });
    }

    function successInfo(info) {
        layer.alert(info,{
            title: title,
            icon: 1,
            closeBtn: 1, //不显示关闭按钮
            anim: 0,
            shadeClose: true, //开启遮罩关闭
        });
    }

</script>
</body>
</html>
